<template>
  <div class="app-container">
    <div>
      <el-form>
        <el-row class="rowFormItem">
          <el-col :span="3">
             <el-select v-model="status" placeholder="禁用或启用">
               <el-option v-for="opt in options" :key="opt.id" :value="opt.id" :label="opt.label" />
             </el-select>
          </el-col>
          <!-- 提交按钮 -->
          <el-col :span="5" class="clear">
            <el-form-item style="text-align: center;width: 250px;margin-left: 10px;">
              <el-button type="primary" size="large" @click="handleSubmit()">检索</el-button>
              <el-button type="warning" size="large" style="margin-left: 8px" @click="handleReset()">重置</el-button>
              <el-button type="success" size="large" @click="addmodel()">添加</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <div class="tableClass">
      <el-table :data="formdata" v-loading="loading" :header-cell-style="{background:'#eef1f6',color:'#606266'}" border
        style="width: 100%;">
        <el-table-column align="center" prop="id" label="序号" />
        <el-table-column align="center" prop="name" label="类型名称" />
        <el-table-column align="center" prop="desc" label="类型简介" />
        <el-table-column align="center" prop="sort" label="排序" />
        <!-- <el-table-column align="center" prop="status" label="状态">
          <template slot-scope="scope">
            <el-select v-model="scope.row.status" @change="changAdminStatus(scope.row.id)">
              <el-option v-for="opt in options" :key="opt.id" :value="opt.id" :label="opt.label" />
            </el-select>
          </template>
        </el-table-column> -->
        <el-table-column align="center" prop="status" label="状态">
          <template slot-scope="scope">
            <div v-if="scope.row.status==0"><el-tag size="small" type="danger">禁用</el-tag></div>
            <div v-if="scope.row.status==1"><el-tag size="small">启用</el-tag></div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="created_at" label="创建时间" />
      </el-table>
      <br>
      <!-- 分页 -->
      <div style="text-align: center;">
        <el-pagination background layout="prev, pager, next" @current-change="pageChange" :page-size="pageSize" :total="totalusers" />
      </div>
    </div>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        status:"",
        options: [{
          id: '0',
          label: "禁用"
        }, {
          id: '1',
          label: "启用"
        }],
        loading: false,
        formdata: [],
        courseList:[],
        totalusers: 0, //总行数
        pageSize: 10, //每页几行
        startpage: 1, //起始页
      }
    },
    mounted() {
      this.getCourseJoinInList()
    },
    methods: {
      handleSubmit(){
          this.getCourseJoinInList()
      },
      handleReset(){
        this.status=""
      },
      //获取报名表分页列表
      getCourseJoinInList() {
        this.formdata = []
        let params = {
          "page": this.startpage,
          "limit": this.pageSize,
          "course_id":this.course_id,
          "user_id":this.user_id,
          "start_time":this.start_time,
          "end_time":this.end_time
        }
        //调用后台提供的接口方法
        this.$api.getCourseJoinInList(params).then(res => {
          console.log(res)
          if (res.data.level == "success") {
            this.formdata = res.data.data
            this.totalusers = res.data.page_info.total
            this.loading = false
          } else {
            this.$message.error(res.data.message)
            this.loading = false
          }

        })
      },
      //分页 pageChange当前页发生改变触发函数
      async pageChange(page) {
        this.startpage = page
        this.loading = true
        //调用获取列表的方法
        this.getCourseJoinInList()
      },
    }
  }
</script>
<style scoped="scoped">
  /deep/.el-card__header {
    background-color: #409EFF;
    color: whitesmoke;
  }

  /deep/.el-dialog {
    margin-top: 10vh !important;
    width: 33%;
  }

  .msgDiv {
    width: 80%;
    margin: auto;
    text-align: center;
  }

  .el-input {
    display: flex;
    flex-grow: <2>;
  }
</style>
